package com.wl.dzt.sys.controller.param.shir;

import com.wl.dzt.sys.controller.action.Action;
import com.wl.dzt.sys.controller.param.Param;
import com.wl.dzt.sys.controller.view.View;
import com.wl.dzt.sys.ui.ext.view.ExtFormView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author wl_code@163.com
 * @date 2018/7/5/005
 * @version 1.0
 * @description 中间拦截器
 * 封装了核心控制器方法以及参数的实体对象
 * 
 */
public class ShirHandler {

	/**
	 * 请求
	 */
	private HttpServletRequest request;

	/**
	 * 响应
	 */
	private HttpServletResponse response;

	/**
	 * 视图
	 */
	private View view;

	/**
	 * 动作
	 */
	private Action action;

	/**
	 * 参数
	 */
	private Param param;

	public ShirHandler(HttpServletRequest request, HttpServletResponse response, View view, Action action, Param param) {
		this.request = request;
		this.response = response;
		this.view = view;
		this.action = action;
		this.param = param;
	}

	/**
	 * <b>激活核心控制器的主要函数</b>
	 * <p>
	 * 等同于手动调用了不同试图和动作所对应的方法
	 * </p>
	 * 
	 * @return 跳转地址
	 */
	public String invoke() {
		String result = view.doView(action.doAction(param), response, request);
		// 表单类型 添加 删除 修改会有是否成功
		if (view instanceof ExtFormView) {
			param.setSuccess((boolean) request.getAttribute("success"));
		}
		return result;
	}

	public HttpServletRequest getRequest() {
		return request;
	}

	public HttpServletResponse getResponse() {
		return response;
	}

	public View getView() {
		return view;
	}

	public Action getAction() {
		return action;
	}

	public Param getParam() {
		return param;
	}
}
